#include "OclLapack.h"
#include <clAmdBlas.h>
#include "../AmdConvertEnum.h"
#include "../clUtils.h"
#include "../ClMem.h"

using namespace std;

void OclLapack::ssyr2k(const char* uplo, const char* trans, int n, int k, float alpha,
		const cl_ptr a, int lda,
		const cl_ptr b, int ldb,
		float beta,
		cl_ptr c, int ldc) 
{
	Measure measure("ssyr2k-ocl");
	
	cl_event event;
	CL_CHECK(clAmdBlasSsyr2kEx(clAmdBlasColumnMajor, 
			toAmdUplo(uplo), toAmdTrans(trans), n, k, alpha,
			a.handle, a.offset, lda,
			b.handle, b.offset, ldb,
			beta,
			c.handle, c.offset, ldc,
			1, &queue, 0, NULL, &event));
	
	ClEvent(event).wait();
}

int OclLapack::ssyr2k(char *uplo, char *trans, int *n, int *k, 
		float *alpha, float *a, int *lda, float *b, int *ldb, float *beta, 
		float *c, int *ldc)
{
	size_t ka = (tolower(trans[0]) == 'n') ? *k : *n;
	ClMem<float> memA(queue, (*lda) * ka, a);
	size_t kb = (tolower(trans[0]) == 'n') ? *k : *n;
	ClMem<float> memB(queue, (*ldb) * kb, b);
	size_t sizeC = (*ldc) * (*n);	
    ClMem<float> memC(queue, sizeC, c);

	ssyr2k(uplo, trans, *n, *k, *alpha,
			cl_ptr(memA), *lda, 
			cl_ptr(memB), *ldb,
			*beta,
			cl_ptr(memC), *ldc);

    memC.beginRead(c, 0, sizeC).wait();

	return 0;
}
